<template>
  <div class="app-header">
    <div class="header-right">
      <el-dropdown @command="handleCommand">
        <span class="company header-item">
          <!-- <span class="name"
            >{{ $tx('欢迎', 'SETTING_WELCOM') }} {{ user.userName }}</span
          > -->
          <span class="name">欢迎&nbsp;{{ user.userName }}</span>
        </span>
        <el-dropdown-menu slot="dropdown" style="min-width:160px">
          <el-dropdown-item v-show="false" command="change_pwd"
            >修改密码</el-dropdown-item
          >
          <!-- <el-dropdown-item command="logout">{{
            $tx('注销', 'SETTING_LOGOUT')
          }}</el-dropdown-item> -->
          <el-dropdown-item command="logout">注销</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <!-- <change-password-dialog ref="dlgPassword" /> -->
    <!-- <change-avatar-dialog ref="dlgAvatar" /> -->
  </div>
</template>

<script>
import defaultAvatar from '@/assets/imgs/default_avatar.png';
import { locales } from '@/config/i18n-map';
// import keycloak from '../../../assets/js/keycloak';
export default {
  components: {},
  data() {
    return {
      defaultAvatar: defaultAvatar,
      passwordDialogVisible: false,
      avatarDialogVisible: false
    };
  },
  computed: {
    user() {
      return this.$store.state.user;
    },
    avatarUrl() {
      var avatarUrl = this.user.avatarUrl;
      if (rt.isNullOrWhiteSpace(avatarUrl)) {
        return null;
      }

      return rt.getBaseURL() + avatarUrl;
    },
    locales() {
      return locales;
    },
    selectedLocale() {
      if (rt.isNullOrWhiteSpace(this.$i18n.locale)) {
        return this.locales[0];
      }
      for (var i = 0; i < this.locales.length; i++) {
        if (this.locales[i].value === this.$i18n.locale) {
          return this.locales[i];
        }
      }
    }
  },
  created() {},
  methods: {
    //语言选择
    setLanguage(locale) {
      //   this.$i18n.locale = locale;
      localStorage.i18nLocale = locale;

      location.reload();
    },
    handleCommand(command) {
      if (command == 'change_pwd') {
        this.showPasswordDialog();
      } else if (command == 'change_avatar') {
        this.showAvatarDialog();
      } else if (command == 'logout') {
        this.logout();
      }
    },
    logout() {
      this.$keycloak.logoutFn(() => {
        rt.logout();
      });
    },
    showAvatarDialog() {
      this.$refs.dlgAvatar.show();
    },
    showPasswordDialog() {
      this.$refs.dlgPassword.show();
    }
  }
};
</script>

<style lang="less" scoped>
.app-header {
  height: 64px;
  padding: 0;
  background: #fff;
  box-shadow: 0px 2px 4px 2px rgba(187, 194, 221, 0.3);
  position: relative;
  z-index: 1;
  .header-index-trigger {
    font-size: 20px;
    display: inline-block;
    cursor: pointer;
    transition: all 0.3s, padding 0s;
    padding: 22px 24px;
  }

  .header-index-trigger:hover {
    background: rgba(0, 0, 0, 0.025);
  }

  svg {
    fill: rgba(0, 0, 0, 0.65);
  }

  .icon-menu-fold {
    display: inline-block;
    font-style: normal;
    vertical-align: -0.125em;
    text-align: center;
    text-transform: none;
    line-height: 0;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .header-item {
    padding: 0 12px;
    display: inline-block;
    transition: all 0.3s;
    height: 100%;
    display: flex;
    align-items: center;
  }

  .header-item.header-item-action {
    cursor: pointer;
  }

  .header-item.header-item-action:hover {
    background: rgba(0, 0, 0, 0.025);
  }

  .header-right {
    float: right;
    height: 100%;
    overflow: hidden;
    display: flex;

    .company {
      .name {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.65);
        display: inline-block;
        vertical-align: middle;
      }
    }

    .account {
      .avatar {
        margin-right: 8px;

        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: inline-block;
      }

      .name {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.65);
      }
    }

    .lang {
      i {
        color: rgba(0, 0, 0, 0.65);
      }
    }
  }
}
</style>
